{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import mytools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "数据表 = pd.read_excel(R'data\\外观设计和屏幕设计.xlsx')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据分析流程\n",
    "\n",
    "明确目标-->获取数据-->数据清理-->数据分析-->汇报结果\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据清理\n",
    "\n",
    "1. 清理空白值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "数据表.dropna(how='any',inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. 删除重复值\n",
    "   判断数据重复的依据是日期和公司名称"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编码员</th>\n",
       "      <th>日期</th>\n",
       "      <th>公司名称</th>\n",
       "      <th>链接</th>\n",
       "      <th>企业价值观</th>\n",
       "      <th>购买动机</th>\n",
       "      <th>忠诚度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2023年11月3日</td>\n",
       "      <td>1</td>\n",
       "      <td>https://mp.weixin.qq.com/s/6AnyScVO6PvsMR-ABcIc3w</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5</td>\n",
       "      <td>2023年11月3日</td>\n",
       "      <td>1</td>\n",
       "      <td>https://mp.weixin.qq.com/s/6AnyScVO6PvsMR-ABcIc3w</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2023年11月3日</td>\n",
       "      <td>1</td>\n",
       "      <td>https://mp.weixin.qq.com/s/6AnyScVO6PvsMR-ABcIc3w</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>2023年11月3日</td>\n",
       "      <td>1</td>\n",
       "      <td>https://mp.weixin.qq.com/s/6AnyScVO6PvsMR-ABcIc3w</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>2023年11月3日</td>\n",
       "      <td>1</td>\n",
       "      <td>https://mp.weixin.qq.com/s/6AnyScVO6PvsMR-ABcIc3w</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>212</th>\n",
       "      <td>2</td>\n",
       "      <td>2023年7月29日</td>\n",
       "      <td>4</td>\n",
       "      <td>https://mp.weixin.qq.com/s/tkkFwsQYM3ZSXjSx6rSLVA</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>213</th>\n",
       "      <td>4</td>\n",
       "      <td>2023年7月29日</td>\n",
       "      <td>4</td>\n",
       "      <td>https://mp.weixin.qq.com/s/tkkFwsQYM3ZSXjSx6rSLVA</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>214</th>\n",
       "      <td>7</td>\n",
       "      <td>2023年7月29日</td>\n",
       "      <td>4</td>\n",
       "      <td>https://mp.weixin.qq.com/s/tkkFwsQYM3ZSXjSx6rSLVA</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>215</th>\n",
       "      <td>6</td>\n",
       "      <td>2023年7月29日</td>\n",
       "      <td>4</td>\n",
       "      <td>https://mp.weixin.qq.com/s/tkkFwsQYM3ZSXjSx6rSLVA</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>216</th>\n",
       "      <td>3</td>\n",
       "      <td>2023年7月29日</td>\n",
       "      <td>4</td>\n",
       "      <td>https://mp.weixin.qq.com/s/tkkFwsQYM3ZSXjSx6rSLVA</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>187 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     编码员          日期  公司名称                                                 链接  \\\n",
       "1      1  2023年11月3日     1  https://mp.weixin.qq.com/s/6AnyScVO6PvsMR-ABcIc3w   \n",
       "2      5  2023年11月3日     1  https://mp.weixin.qq.com/s/6AnyScVO6PvsMR-ABcIc3w   \n",
       "3      4  2023年11月3日     1  https://mp.weixin.qq.com/s/6AnyScVO6PvsMR-ABcIc3w   \n",
       "4      7  2023年11月3日     1  https://mp.weixin.qq.com/s/6AnyScVO6PvsMR-ABcIc3w   \n",
       "5      6  2023年11月3日     1  https://mp.weixin.qq.com/s/6AnyScVO6PvsMR-ABcIc3w   \n",
       "..   ...         ...   ...                                                ...   \n",
       "212    2  2023年7月29日     4  https://mp.weixin.qq.com/s/tkkFwsQYM3ZSXjSx6rSLVA   \n",
       "213    4  2023年7月29日     4  https://mp.weixin.qq.com/s/tkkFwsQYM3ZSXjSx6rSLVA   \n",
       "214    7  2023年7月29日     4  https://mp.weixin.qq.com/s/tkkFwsQYM3ZSXjSx6rSLVA   \n",
       "215    6  2023年7月29日     4  https://mp.weixin.qq.com/s/tkkFwsQYM3ZSXjSx6rSLVA   \n",
       "216    3  2023年7月29日     4  https://mp.weixin.qq.com/s/tkkFwsQYM3ZSXjSx6rSLVA   \n",
       "\n",
       "     企业价值观  购买动机  忠诚度  \n",
       "1        2     1    1  \n",
       "2        2     1    1  \n",
       "3        2     2    1  \n",
       "4        2     1    1  \n",
       "5        2     1    1  \n",
       "..     ...   ...  ...  \n",
       "212      2     2    0  \n",
       "213      2     2    0  \n",
       "214      2     2    0  \n",
       "215      2     2    0  \n",
       "216      2     2    0  \n",
       "\n",
       "[187 rows x 7 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看重复值\n",
    "数据表[数据表.duplicated(subset=['日期','公司名称'], keep='first')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除重复值\n",
    "数据表.drop_duplicates(subset=['日期','公司名称'], keep='first',inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "编码员       int64\n",
       "日期       object\n",
       "公司名称      int64\n",
       "链接       object\n",
       "企业价值观     int64\n",
       "购买动机      int64\n",
       "忠诚度       int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "数据表.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "def 重新变量数值到标签(value):\n",
    "    if value == 1:\n",
    "        return '苹果'\n",
    "    elif value == 2:\n",
    "        return '华为'\n",
    "    elif value == 3:\n",
    "        return '小米'\n",
    "    elif value == 4:\n",
    "        return '三星'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "数据表['公司'] = 数据表['公司名称'].apply(重新变量数值到标签)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "数据表['价值观'] = 数据表['企业价值观'].map({1:\"追求创新\",2:\"用户至上\",3:\"社会责任\"})\n",
    "数据表['动机'] = 数据表['购买动机'].map({1:\"追求性能\",2:\"追求新颖\",3:\"追求名利\"})\n",
    "数据表['忠诚'] = 数据表['忠诚度'].map({0:\"无\",1:\"不强\",2:\"强\",3:\"非常强\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>公司</th>\n",
       "      <th>个数</th>\n",
       "      <th>百分比</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>华为</td>\n",
       "      <td>8</td>\n",
       "      <td>26.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>小米</td>\n",
       "      <td>8</td>\n",
       "      <td>26.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>苹果</td>\n",
       "      <td>7</td>\n",
       "      <td>23.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>三星</td>\n",
       "      <td>7</td>\n",
       "      <td>23.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>总和</td>\n",
       "      <td>30</td>\n",
       "      <td>100.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   公司  个数     百分比\n",
       "0  华为   8   26.67\n",
       "1  小米   8   26.67\n",
       "2  苹果   7   23.33\n",
       "3  三星   7   23.33\n",
       "4  总和  30  100.00"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mytools.gen_percent_table(数据表,'公司')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>编码员</th>\n",
       "      <td>int64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日期</th>\n",
       "      <td>object</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>公司名称</th>\n",
       "      <td>category</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>链接</th>\n",
       "      <td>object</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>企业价值观</th>\n",
       "      <td>category</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>购买动机</th>\n",
       "      <td>category</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>忠诚度</th>\n",
       "      <td>category</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              0\n",
       "编码员       int64\n",
       "日期       object\n",
       "公司名称   category\n",
       "链接       object\n",
       "企业价值观  category\n",
       "购买动机   category\n",
       "忠诚度    category"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 指定变量的类型\n",
    "df4 = 数据表.astype({\n",
    "    '公司名称': 'category',\n",
    "    '企业价值观': 'category',\n",
    "    '购买动机': 'category',\n",
    "    '忠诚度': 'category',\n",
    "})\n",
    "df4.dtypes.to_frame()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      不强\n",
       "7      不强\n",
       "14      强\n",
       "21      无\n",
       "28      无\n",
       "42      强\n",
       "49      无\n",
       "56      强\n",
       "63      强\n",
       "70     不强\n",
       "77      强\n",
       "84     不强\n",
       "91      强\n",
       "98      无\n",
       "105     强\n",
       "112    不强\n",
       "119     强\n",
       "126     无\n",
       "133     强\n",
       "140     强\n",
       "147    不强\n",
       "154     无\n",
       "161     强\n",
       "168    不强\n",
       "175    不强\n",
       "182     无\n",
       "189    不强\n",
       "196     无\n",
       "203     无\n",
       "210     无\n",
       "Name: 忠诚度, dtype: category\n",
       "Categories (3, object): ['无', '不强', '强']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df4.copy()\n",
    "df.公司名称.cat.categories\n",
    "df.公司名称.cat.rename_categories({1: \"苹果\", 2: \"华为\", 3: \"小米\", 4: \"三星\"})\n",
    "df.企业价值观.cat.rename_categories({1: \"追求创新\", 2: \"用户至上\", 3: \"社会责任\"})\n",
    "df.购买动机.cat.rename_categories({1: \"追求性能\", 2: \"追求新颖\", 3: \"追求名利\"})\n",
    "df.忠诚度.cat.rename_categories({0:\"无\", 1: \"不强\", 2: \"强\", 3: \"非常强\"})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      1\n",
       "7      1\n",
       "14     2\n",
       "21     0\n",
       "28     0\n",
       "42     2\n",
       "49     0\n",
       "56     2\n",
       "63     2\n",
       "70     1\n",
       "77     2\n",
       "84     1\n",
       "91     2\n",
       "98     0\n",
       "105    2\n",
       "112    1\n",
       "119    2\n",
       "126    0\n",
       "133    2\n",
       "140    2\n",
       "147    1\n",
       "154    0\n",
       "161    2\n",
       "168    1\n",
       "175    1\n",
       "182    0\n",
       "189    1\n",
       "196    0\n",
       "203    0\n",
       "210    0\n",
       "Name: 忠诚度, dtype: category\n",
       "Categories (3, int64): [0 < 1 < 2]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 设置忠诚度为有序类别变量\n",
    "df.忠诚度.cat.as_ordered()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据分析\n",
    "先进行单变量描述统计\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>公司名称</th>\n",
       "      <th>个数</th>\n",
       "      <th>百分比</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>26.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>26.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>23.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>23.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>总和</td>\n",
       "      <td>30</td>\n",
       "      <td>100.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  公司名称  个数     百分比\n",
       "0    2   8   26.67\n",
       "1    3   8   26.67\n",
       "2    1   7   23.33\n",
       "3    4   7   23.33\n",
       "4   总和  30  100.00"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mytools.gen_percent_table(df,'公司名称')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>企业价值观</th>\n",
       "      <th>个数</th>\n",
       "      <th>百分比</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>14</td>\n",
       "      <td>46.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>43.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>10.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>总和</td>\n",
       "      <td>30</td>\n",
       "      <td>100.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  企业价值观  个数     百分比\n",
       "0     1  14   46.67\n",
       "1     2  13   43.33\n",
       "2     3   3   10.00\n",
       "3    总和  30  100.00"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mytools.gen_percent_table(df,'企业价值观')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tau_y系数: 0.0426 极弱相关或无相关\n",
      "----  -  -  -\n",
      "三星  4  1  2\n",
      "华为  3  1  4\n",
      "小米  3  0  5\n",
      "苹果  3  1  3\n",
      "----  -  -  -\n",
      "卡方值： 2.50, p值： 0.8681,自由度:6。\n",
      "接受虚无假设\n"
     ]
    }
   ],
   "source": [
    "# 双变量统计分析\n",
    "mytools.两个无序类别变量的统计分析(数据表,'公司','价值观')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tau_y系数: 0.1346 极弱相关或无相关\n",
      "----  -  -  -\n",
      "三星  3  0  4\n",
      "华为  2  5  1\n",
      "小米  2  4  2\n",
      "苹果  2  2  3\n",
      "----  -  -  -\n",
      "卡方值： 7.65, p值： 0.2650,自由度:6。\n",
      "接受虚无假设\n"
     ]
    }
   ],
   "source": [
    "mytools.两个无序类别变量的统计分析(数据表,'公司','忠诚')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
